package com.com.effectivejava.objectcreation;

/**
 * Created by pankaj on 7/6/14.
 *
 * 1. This class is an example of instance-controlled class.True instance controlled
 * class example would be jrevision EditionDB class. one instance for each DB is there.
 * 2. Singleton class: Returns the same object on every invocation.
 * 3.
 *
 *
 */

public class StaticFactoryMethods {
    private static StaticFactoryMethods instance = null;

    private StaticFactoryMethods(){

    }
    //Not Thread safe.
    public static StaticFactoryMethods getInstance() {
        if (instance == null) {
            instance = new StaticFactoryMethods();
        }
        return instance;
    }

    public static void main(String... a) {
        StaticFactoryMethods ins = getInstance();
        System.out.println(ins);

        StaticFactoryMethods ins2 = getInstance();
        System.out.println(ins2);
    }
}

/* example of how classes without public or private constructor cannot be subclassed.
class Subclass extends StaticFactoryMethods{

}*/
